<template>
	<view class="container">
		<view class="goods-item">
			<label class="title">商品</label>
			<label class="content">{{ goodsName }}</label>
		</view>
		<view class="goods-item">
			<label class="title">价格</label>
			<label class="content">￥{{ truePrice }}</label>
		</view>
		<view class="goods-item">
			<label class="title">描述</label>
			<rich-text :nodes="goodsSubName" class="content remark"></rich-text>
		</view>
		<view class="goods-item">
			<label class="title">积分</label>
			<label class="content">{{ point }}</label>
		</view>
		<view class="footer"><view class="goToBuy" @tap="goToBuy">购买</view></view>
	</view>
</template>

<script>
import parseHtml from '@/util/html-parser.js';
import { getGoodsInfo } from '@/api/mall.js';
import { pay } from '@/common/pay.js';
// #ifdef H5
import routeUtil from '@/util/routeUtil.js';
// #endif
export default {
	data() {
		return {
			goodsId: '',
			goodsName: '',
			truePrice: '',
			goodsSubName: '',
			point: 0,
			isIOS:false
		};
	},
	onLoad(e) {		
		// #ifdef H5
		routeUtil.reloadUrlHandler();
		// #endif
		// #ifdef MP-WEIXIN
		this.isIOS = uni.getSystemInfoSync().platform == 'ios';
		// #endif
		if (this.isIOS) {
			uni.showModal({
				title: '提示',
				content: 'IOS暂不支持购买',
				showCancel: false,
				success() {
					uni.switchTab({
						url: '../index/index'
					});
				}
			});
		} else {
			this.goodsId = e.Id;
			this.bindGoods(e.Id);
		}
	},
	onShareAppMessage(e) {
		return {
			path: this.$handlerAppMessagePath()
		};
	},
	methods: {
		bindGoods(id) {
			var that = this;
			getGoodsInfo(id).then(res => {
				that.goodsName = res.goodsName;
				that.truePrice = res.truePrice;
				that.goodsSubName = parseHtml(res.goodsSubName);
				that.point = res.point || 0;
				uni.setNavigationBarTitle({
					title: res.goodsName
				});
				// #ifdef H5
				that.$wechat.share({
					link: that.$handlerAppMessagePath()
				});
				// #endif
			});
		},
		goToBuy() {
			pay({ point: this.point, orderItems: [{ goodsId: this.goodsId, count: 1, canGift: false }] }, function() {
				uni.switchTab({
					url: '../index/index'
				});
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
}
.goods-item {
	width: 100%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid $uni-color-divider;
	font-size: 40rpx;
	min-height: 100rpx;
	.title {
		padding-left: 30rpx;
		width: 20%;
		flex-shrink: 0;
	}
	.content {
		padding-right: 30rpx;
	}
	.remark {
		font-size: 35rpx;
		padding: 20rpx 30rpx 20rpx 0;
	}
}
.footer {
	position: fixed;
	bottom: 0;
	width: 100%;
	.goToBuy {
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		background: $uni-color-main-dark;
		color: #ffffff;
		text-align: center;
		font-size: 50rpx;
		letter-spacing: 10rpx;
	}
}
</style>
